using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Acms.SqlDal
{
    public partial class Site : GeneratedSite
    {

    }

    public abstract class GeneratedSite : Base, Acms.DalInterface.ISite
    {
        protected override System.Collections.Hashtable PopulateHashTable(SqlDataReader reader)
        {
            Hashtable tmp = new Hashtable();
            tmp[Acms.DalInterface.SiteFields.Id] = GetValue(reader, Acms.DalInterface.SiteFields.Id.ToString());
            tmp[Acms.DalInterface.SiteFields.Name] = GetValue(reader, Acms.DalInterface.SiteFields.Name.ToString());
            tmp[Acms.DalInterface.SiteFields.RootUrl] = GetValue(reader, Acms.DalInterface.SiteFields.RootUrl.ToString());
            tmp[Acms.DalInterface.SiteFields.Created] = GetValue(reader, Acms.DalInterface.SiteFields.Created.ToString());
            tmp[Acms.DalInterface.SiteFields.Cid] = GetValue(reader, Acms.DalInterface.SiteFields.Cid.ToString());
            return tmp;
        }

        public virtual System.Collections.Hashtable GetById(int id)
        {
            SqlCommand cmd = CreateCommand("Site_GetById");
            cmd.Parameters.Add(CreateInputParameter("Id", SqlDbType.Int, id, null, null, null));
            return ExecuteGetItem(cmd);
            
        }

        public virtual System.Collections.Hashtable GetByRootUrl(string url)
        {
            SqlCommand cmd = CreateCommand("Site_GetByRootUrl");
            cmd.Parameters.Add(CreateInputParameter("RootUrl", SqlDbType.VarChar, url, 20, null, null));
            return ExecuteGetItem(cmd);
        }

        public virtual System.Collections.Hashtable[] GetAll()
        {
            SqlCommand cmd = CreateCommand("Site_GetAll");
            return ExecuteGetCollection(cmd);
        }

        public virtual void SaveChanges(int id, string name, string rootUrl, int cid, ref int idOut, ref DateTime createdOut, ref int cidOut)
        {
            SqlCommand cmd = CreateCommand("Site_Put");
            cmd.Parameters.Add(CreateInputParameter("Id", SqlDbType.Int, id, null, null, null));
            cmd.Parameters.Add(CreateInputParameter("Name", SqlDbType.VarChar, name, 50, null, null));
            cmd.Parameters.Add(CreateInputParameter("RootUrl", SqlDbType.VarChar, rootUrl, 255, null, null));
            cmd.Parameters.Add(CreateInputParameter("Cid", SqlDbType.Int, cid, null, null, null));
            cmd.Parameters.Add(CreateOutputParameter("IdOut", SqlDbType.Int, null, null, null));
            cmd.Parameters.Add(CreateOutputParameter("CreatedOut", SqlDbType.DateTime, null, null, null));
            cmd.Parameters.Add(CreateOutputParameter("CidOut", SqlDbType.DateTime, null, null, null));
            ExecuteNonQuery(cmd);
            SetReturnValue(ref idOut, "IdOut", cmd);
            SetReturnValue(ref createdOut, "CreatedOut", cmd);
            SetReturnValue(ref cidOut, "CidOut", cmd);

        }

        public virtual void Delete(int id)
        {
            SqlCommand cmd = CreateCommand("Site_Delete");
            cmd.Parameters.Add(CreateInputParameter("Id", SqlDbType.Int, id, null, null, null));
            ExecuteNonQuery(cmd);
        }

    }

    public partial class Page : GeneratedPage
    {
    }

    public abstract class GeneratedPage: Base, Acms.DalInterface.IPage  
    {
        protected override System.Collections.Hashtable PopulateHashTable(SqlDataReader reader)
        {
            Hashtable tmp = new Hashtable();
            tmp[Acms.DalInterface.PageFields.Id] = GetValue(reader, Acms.DalInterface.PageFields.Id.ToString());
            tmp[Acms.DalInterface.PageFields.VersionId] = GetValue(reader, Acms.DalInterface.PageFields.VersionId.ToString());
            tmp[Acms.DalInterface.PageFields.SiteId] = GetValue(reader, Acms.DalInterface.PageFields.SiteId.ToString());
            tmp[Acms.DalInterface.PageFields.ParentId] = GetValue(reader, Acms.DalInterface.PageFields.ParentId.ToString());
            tmp[Acms.DalInterface.PageFields.Name] = GetValue(reader, Acms.DalInterface.PageFields.Name.ToString());
            tmp[Acms.DalInterface.PageFields.DisplayName] = GetValue(reader, Acms.DalInterface.PageFields.DisplayName.ToString());
            return tmp;
        }

        public virtual System.Collections.Hashtable[] GetRoot(int siteId)
        {
            SqlCommand cmd = CreateCommand("Page_GetRoot");
            cmd.Parameters.Add(CreateInputParameter("SiteId", SqlDbType.Int, siteId, null, null, null));
            return ExecuteGetCollection(cmd);
        }

        public virtual Hashtable[] GetByParentId(int parentId)
        {
            SqlCommand cmd = CreateCommand("Page_GetByParentId");
            cmd.Parameters.Add(CreateInputParameter("ParentId", SqlDbType.Int, parentId, null, null, null));
            return ExecuteGetCollection(cmd);
        }

        public virtual void SaveChanges(int id, int versionId, int siteId, int? parentId, string name, string displayName, ref int idOut, ref int versionIdOut)
        {
            SqlCommand cmd = CreateCommand("Site_Put");
            cmd.Parameters.Add(CreateInputParameter("Id", SqlDbType.Int, id, null, null, null));
            cmd.Parameters.Add(CreateInputParameter("VersionId", SqlDbType.Int,  versionId, null, null, null));
            cmd.Parameters.Add(CreateInputParameter("SiteId", SqlDbType.Int,  siteId, null, null, null));
            cmd.Parameters.Add(CreateInputParameter("ParentId", SqlDbType.Int,  parentId, null, null, null));
            cmd.Parameters.Add(CreateInputParameter("Name", SqlDbType.VarChar,  name, 50, null, null));
            cmd.Parameters.Add(CreateInputParameter("DisplayName", SqlDbType.VarChar,  displayName, 50, null, null));
            cmd.Parameters.Add(CreateOutputParameter("IdOut", SqlDbType.Int, null, null, null));
            cmd.Parameters.Add(CreateOutputParameter("VersionIdOut", SqlDbType.Int, null, null, null));
            ExecuteNonQuery(cmd);
            SetReturnValue(ref idOut, "IdOut", cmd);
            SetReturnValue(ref versionIdOut, "VersionIdOut", cmd);

        }

        public virtual void Delete(int id)
        {
            SqlCommand cmd = CreateCommand("Site_Delete");
            cmd.Parameters.Add(CreateInputParameter("Id", SqlDbType.Int, id, null, null, null));
            ExecuteNonQuery(cmd);
        }
    }

}
